<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <ul>
      <li v-for="cate in cates" :key="cate.id">
        <img :src="cate.icon" alt="">
        <h5>{{cate.name}}</h5>
      </li>
    </ul>
    <ul>
      <li v-for="item in items" :key="item.id">
        <img :src="item.pic" alt="">
        <h5>{{item.name}}</h5>
      </li>
    </ul>
  </div>
  <script src="./vue.js"></script>
  <script src="./axios.js"></script>
  <script>
 
    // 创建axios实例
   /*  const request = axios.create({
      baseURL: 'https://api.it120.cc/conner',
      timeout: 5000
    }) */
    axios.defaults.baseURL = 'https://api.it120.cc/conner';
    axios.defaults.timeout = 5000;
    const vm = new Vue({
      el: '#app',
      data: {
        cates: [],
        items: []
      },
      created(){
        this.fetchCates();
        this.fetchItems();
      },
      methods:{ 
        fetchCates(){
          axios.get('/shop/goods/category/all', {
            params: {
              a: 10,
              b: 20
            }
          }).then(res=>{
            if(res.data.code ===0){
              this.cates = res.data.data
            }
          })
        },
        fetchItems(){
          axios.post('/shop/goods/list/v2', {
            a: 10,
            b: 20
          }).then(res=> {
            if(res.data.code === 0) {
              this.items = res.data.data.result
            }
          })
        }
      }
    })
  </script>
</body>
</html>